/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2022 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "i2c.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include <string.h>
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define REV_OK		0	//接收完成标志
#define REV_WAIT	1	//接收未完成标志
#define ESP8266_WIFI_INFO		"AT+CWJAP=\"RedmiK70\",\"12345678\"\r\n"
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
//支持printf函数串口发送
#if 1
#pragma import(__use_no_semihosting)

struct __FILE
{
	int handle;
};
FILE __stdout;
void _sys_exit(int x)//避免半主机模式
{
		x=x;
}
int fputc(int ch,FILE *f)
{
	while((USART1->SR&0X40)==0);//循环发送，直到发送完毕
	USART1->DR=(uint8_t)ch;
	return ch;
}
#endif

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint8_t aRxBuffer1;//一个字节的缓冲
uint8_t hometemp;	 //模拟室温
void ESP8266_MQTT_Init(void);
void MQTT_SendData(unsigned int temp,unsigned int humidity,unsigned co2);
char ledtemp[256];
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */
	
  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_I2C1_Init();
  MX_TIM3_Init();
  MX_TIM2_Init();
  /* USER CODE BEGIN 2 */
   
    HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);	
	HAL_UART_Receive_IT(&huart1,&aRxBuffer1,1); //使能串口接收中断
    OLED_Init();                           //OLED初始化
    OLED_Clear();
    ESP8266_MQTT_Init();
    uint8_t temperature = 1;                     //温度值
    uint8_t humidity = 1;                        //湿度值
    DHT11_Rst();
    HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
	sprintf(ledtemp,"AT+MQTTPUB=0,\"$oc/devices/67bd7f9b8e04aa0690b7e606_shebei2/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"server\\\"\\,\\\"properties\\\":{\\\"led\\\":0}}]}\",0,0\r\n");        //		AT_write(pubco2);
    ESP8266_SendCmd(ledtemp, "OK");
    
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
        
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
      unsigned int co2=500;
      DHT11_Read_Data(&humidity,&temperature);
      OLED_ShowString(0,0,"co2:",16,0);
      OLED_ShowNum(36,0,co2,3,16,0);
      OLED_ShowString(0,2,"temp:",16,0);
      OLED_ShowNum(48,2,temperature,2,16,0);
      OLED_ShowString(0,4,"humidity:",16,0);
      OLED_ShowNum(80,4,humidity,2,16,0); 
      MQTT_SendData(temperature,humidity,co2);
      if(humidity>=95||temperature>=30)
      {
          HAL_GPIO_WritePin(BEEP_GPIO_Port,BEEP_Pin,GPIO_PIN_RESET);
      }
      else
      {
          HAL_GPIO_WritePin(BEEP_GPIO_Port,BEEP_Pin,GPIO_PIN_SET);
      }
      HAL_Delay(200);      
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */
unsigned char esp8266_buf[256];
unsigned short esp8266_cnt = 0, esp8266_cntPre = 0;


//mqtt全局变量
	unsigned short timeCount = 0;	//发送间隔变量
		
	unsigned char *dataPtr = NULL;
	char PubBuf[100] = {0};//数据缓冲区

void delay(int t)
{
	int i,j=0;
	for(i=0;i<5000;i++)
		for(j=0;j<t;j++);
}
//==========================================================
//	函数名称：	ESP8266_Clear
//
//	函数功能：	清空缓存
//
//	入口参数：	无
//
//	返回参数：	无
//
//	说明：		
//==========================================================
void ESP8266_Clear(void)
{

	memset(esp8266_buf, 0, sizeof(esp8266_buf));
	esp8266_cnt = 0;

}

//==========================================================
//	函数名称：	ESP8266_WaitRecive
//
//	函数功能：	等待接收完成
//
//	入口参数：	无
//
//	返回参数：	REV_OK-接收完成		REV_WAIT-接收超时未完成
//
//	说明：		循环调用检测是否接收完成
//==========================================================
_Bool ESP8266_WaitRecive(void)
{

	if(esp8266_cnt == 0) 							//如果接收计数为0 则说明没有处于接收数据中，所以直接跳出，结束函数
		return REV_WAIT;
		
	if(esp8266_cnt == esp8266_cntPre)				//如果上一次的值和这次相同，则说明接收完毕
	{
		esp8266_cnt = 0;							//清0接收计数
			
		return REV_OK;								//返回接收完成标志
	}
		
	esp8266_cntPre = esp8266_cnt;					//置为相同
	
	return REV_WAIT;								//返回接收未完成标志

}

//==========================================================
//	函数名称：	ESP8266_SendCmd
//
//	函数功能：	发送命令
//
//	入口参数：	cmd：命令
//				res：需要检查的返回指令
//
//	返回参数：	0-成功	1-失败
//
//	说明：		
//==========================================================
_Bool ESP8266_SendCmd(char *cmd, char *res)
{
	
	unsigned char timeOut = 200;

	Usart_SendString_8266(&huart1, (unsigned char *)cmd, strlen((const char *)cmd));
	
	while(timeOut--)
	{
		if(ESP8266_WaitRecive() == REV_OK)							//如果收到数据
		{
			if(strstr((const char *)esp8266_buf, res) != NULL)		//如果检索到关键词
			{
				ESP8266_Clear();									//清空缓存
				
				return 0;
			}
		}
		
		HAL_Delay(10);
		
	}
	
	return 1;

}

//==========================================================
//	函数名称：	ESP8266_SendData
//
//	函数功能：	发送数据
//
//	入口参数：	data：数据
//				len：长度
//
//	返回参数：	无
//
//	说明：		
//==========================================================
void ESP8266_SendData(unsigned char *data, unsigned short len)
{

	char cmdBuf[32];
	
	ESP8266_Clear();								//清空接收缓存
	sprintf(cmdBuf, "AT+CIPSEND=%d\r\n", len);		//发送命令
	if(!ESP8266_SendCmd(cmdBuf, ">"))				//收到‘>’时可以发送数据
	{
		Usart_SendString_8266(&huart1, data, len);		//发送设备连接请求数据
	}

}
////重写串口接收中断回调函数
//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
//{
//	char analysis_Str[256];
//	if(huart->Instance == USART1)
//	{
//		HAL_UART_Receive_IT(&huart1,&aRxBuffer1,1);
//		// save char from uart receive
//		if(aRxBuffer1!='\n')
//			R_data[R_length++]=aRxBuffer1;
//		else
//		{
//			if(R_length>=5)
//			{
//					if(R_data[0]=='r'&&R_data[1]=='e'&&R_data[2]=='a'&&R_data[3]=='d'&&R_data[4]=='y')
//					{
//							at_start_flag=1;
//							printf("检测到ready\r\n");
//							memset(R_data,0,sizeof(R_data));//清空缓存区
//					}
//			}
//			if(R_length>200)//我的接收数据长度为201
//			{
//					strncpy(analysis_Str, R_data, 12);//提取出“+MQTTSUBRECV”
//					if(strcmp(analysis_Str,"+MQTTSUBRECV")==0)
//					{
//							memset(analysis_Str,0,sizeof(analysis_Str));//清空缓存区
//							//printf("MQTT命令接收头正确\r\n");
//							strncpy(request_id, R_data+92, 36);		//提取出request_id
//							//printf("request_id=%s\r\n",request_id);
//							strncpy(analysis_Str, R_data+135, 5);	//提取出"paras"
//							//printf("paras=%s\r\n",analysis_Str);
//							if(strcmp(analysis_Str,"paras")==0)		//有效参数体
//							{
//									memset(analysis_Str,0,sizeof(analysis_Str));//清空缓存区
//									strncpy(analysis_Str, R_data+144,3);	//提取出"led"
//									//printf("att is %s\r\n",analysis_Str);
//									if(strcmp(analysis_Str,"led")==0)
//									{
//											//printf("led set %c",R_data[149]);
//											//printf("AT+MQTTSUB=0,\"$oc/devices/设备ID/sys/commands/response/request_id=%s\",1\r\n",request_id);
//											memset(analysis_Str,0,sizeof(analysis_Str));//清空缓存区
//											if(R_data[149]=='0')
//											{
//													//printf("关灯\r\n");
//                                                    __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, 0);
//													printf("AT+MQTTPUB=0,\"$oc/devices/设备ID/sys/commands/response/request_id=%s\",\"\",0,0\r\n",request_id);
//													HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
//													memset(analysis_Str,0,sizeof(analysis_Str));//清空缓存区	
//	
//											}
//											else if(R_data[149]=='1')
//											{
//													//printf("开灯\r\n");
//													//AT+MQTTPUB=0,"$oc/devices/设备ID/sys/commands/response/request_id=收到的request_id","",0,0
//                                                    __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1,7199);
//													printf("AT+MQTTPUB=0,\"$oc/devices/设备ID/sys/commands/response/request_id=%s\",\"\",0,0\r\n",request_id);
//													memset(analysis_Str,0,sizeof(analysis_Str));//清空缓存区		
//													HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
//											}
//											
//									}		
//							}
//					}
//					else 
//					{
//						//printf("MQTT命令接收头异常:%s\r\n",analysis_Str);
//						memset(analysis_Str,0,sizeof(analysis_Str));//清空缓存区
//					}
//			}
//			//else printf("MQTT命令长度异常，长度：%d",R_length);
//					
//			R_length=0;
//		}

//	}
//}
//void AT_write(char atstring[1024])//阻塞等待OK
//{
//	printf("%s",atstring);
//	while(1)
//	{
//			if(R_data[0]=='O'&&R_data[1]=='K') break;
//			else if(R_data[0]=='b'&&R_data[1]=='u'&&R_data[2]=='s'&&R_data[3]=='y')
//			{
//				
//			}

//			else delay(50);
//	}
//	R_data[0]=R_data[1]=0;
//	delay(50);
//}
void ESP8266_MQTT_Init(void)
{
//	uint8_t i=0;
//	for(i=0;i<10;i++)
//	{
//		if(at_start_flag==1)
//		{
//			AT_write("AT\r\n");
//			printf("AT+RST\r\n");
//			delay(1000);
//			AT_write("AT\r\n");
//			AT_write("AT+CWMODE=1\r\n");
//        AT_write("AT+CWJAP=\"wifi名称\",\"wifi密码\"\r\n");
//        AT_write("AT+MQTTUSERCFG=0,1,\"NULL\",\"三元组之Username\",\"三元组之password\",0,0,\"\"\r\n");
//        AT_write("AT+MQTTCLIENTID=0,\"三元组之ClientID\"\r\n");
//        AT_write("AT+MQTTCONN=0,\"MQTT接入地址\",1883,1\r\n");
//        AT_write("AT+MQTTSUB=0,\"$oc/devices/设备ID/sys/properties/report\",1\r\n");
//        AT_write("AT+MQTTSUB=0,\"$oc/devices/设备ID/sys/commands/#\",1\r\n");
//        AT_write("AT+MQTTSUB=0,\"$oc/devices/设备ID/sys/commands/response/#\",1\r\n");
//            AT_write("AT+CWJAP=\"wifi名称\",\"wifi密码\"\r\n");
//			AT_write("AT+MQTTUSERCFG=0,1,\"NULL\",\"67c05fc124d772325520f98a_000000\",\"8ce9ad4f88c78a7d02c7d67035303dbf826c10faadbf69bd9741eda0193f69a4\",0,0,\"\"\r\n");
//			AT_write("AT+MQTTCLIENTID=0,\"67c05fc124d772325520f98a_000000_0_0_2025022809\"\r\n");
//			AT_write("AT+MQTTCONN=0,\"7acc11ea0d.st1.iotda-device.cn-north-4.myhuaweicloud.com\",1883,1\r\n");
//			AT_write("AT+MQTTSUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/properties/report\",1\r\n");
//			AT_write("AT+MQTTSUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/commands/#\",1\r\n");
//			AT_write("AT+MQTTSUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/commands/response/#\",1\r\n");
//            OLED_ShowNum(80,3,1,2,16,0);
//			break;
//		}	
//		else
//		{
//            OLED_ShowNum(80,3,2,2,16,0);
//			printf("等待模块就绪...\r\n");
//			delay(1000);
//		}			
//	}
//    ESP8266_Clear();
//    while(ESP8266_SendCmd("AT\r\n", "OK"))
////	UsartPrintf(USART_DEBUG, "2. CWMODE\r\n");
//	while(ESP8266_SendCmd("AT+CWMODE=1\r\n", "OK"))
////	UsartPrintf(USART_DEBUG, "3. AT+CWDHCP\r\n");
//	while(ESP8266_SendCmd("AT+CWDHCP=1,1\r\n", "OK"))
//	ESP8266_SendCmd("AT+RST\r\n","");
//    HAL_Delay(50);
//    while(ESP8266_SendCmd(ESP8266_WIFI_INFO, "GOT IP"))
//    HAL_Delay(50);
//    while(ESP8266_SendCmd("AT+MQTTUSERCFG=0,1,\"NULL\",\"67c05fc124d772325520f98a_000000\",\"8ce9ad4f88c78a7d02c7d67035303dbf826c10faadbf69bd9741eda0193f69a4\",0,0,\"\"\r\n", "OK"))
//    HAL_Delay(50);
//    while(ESP8266_SendCmd("AT+MQTTCLIENTID=0,\"67c05fc124d772325520f98a_000000_0_0_2025022809\"\r\n", "OK"))
//    HAL_Delay(50);
//    while(ESP8266_SendCmd("AT+MQTTCONN=0,\"7acc11ea0d.st1.iotda-device.cn-north-4.myhuaweicloud.com\",1883,1\r\n", "OK"));
//    while(ESP8266_SendCmd("AT+MQTTSUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/properties/report\",1\r\n", "OK"))
//    while(ESP8266_SendCmd("AT+MQTTSUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/commands/#\",1\r\n", "OK"))
//    while(ESP8266_SendCmd("AT+MQTTSUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/commands/response/#\",1\r\n", "OK"))





    ESP8266_Clear();
    while(ESP8266_SendCmd("AT\r\n", "OK"))
//	UsartPrintf(USART_DEBUG, "2. CWMODE\r\n");
	while(ESP8266_SendCmd("AT+CWMODE=1\r\n", "OK"))
//	UsartPrintf(USART_DEBUG, "3. AT+CWDHCP\r\n");
	while(ESP8266_SendCmd("AT+CWDHCP=1,1\r\n", "OK"))
	ESP8266_SendCmd("AT+RST\r\n","");
    HAL_Delay(50);
    while(ESP8266_SendCmd(ESP8266_WIFI_INFO, "GOT IP"))
    HAL_Delay(50);
    while(ESP8266_SendCmd("AT+MQTTUSERCFG=0,1,\"NULL\",\"67bd7f9b8e04aa0690b7e606_shebei2\",\"1c49e34afd9547e0ddd2666f069fd242757cf23f9867080e7dfec7da1e8edbc6\",0,0,\"\"\r\n", "OK"))
    HAL_Delay(50);
    while(ESP8266_SendCmd("AT+MQTTCLIENTID=0,\"67bd7f9b8e04aa0690b7e606_shebei2_0_0_2025030312\"\r\n", "OK"))
    HAL_Delay(50);
    while(ESP8266_SendCmd("AT+MQTTCONN=0,\"f07c99f0b3.st1.iotda-device.cn-north-4.myhuaweicloud.com\",1883,1\r\n", "OK"));
    OLED_ShowNum(100,1,1,2,16,0);
}

void MQTT_SendData(unsigned int temp,unsigned int humidity,unsigned co2)
{
	char pubtemp[256];
    char pubhumidity[256];
    char pubco2[256];
//	if(at_start_flag==1)
//	{	
//        //sprintf(pubtemp,"AT+MQTTPUB=0,\"$oc/devices/设备ID/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"����ID\\\"\\,\\\"properties\\\":{\\\"����\\\": %d}}]}\",0,0\r\n",hometemp++);
//		sprintf(pubtemp,"AT+MQTTPUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"SERVER\\\"\\,\\\"properties\\\":{\\\"temp\\\": %d}}]}\",0,0\r\n",99);
//		ESP8266_SendCmd(pubtemp, "OK");
////      AT_write(pubtemp);
//        sprintf(pubhumidity,"AT+MQTTPUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"SERVER\\\"\\,\\\"properties\\\":{\\\"humidity\\\": %d}}]}\",0,0\r\n",88);
//        ESP8266_SendCmd(pubhumidity, "OK");
////		AT_write(pubhumidity);
//        sprintf(pubco2,"AT+MQTTPUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"SERVER\\\"\\,\\\"properties\\\":{\\\"co2\\\": %d}}]}\",0,0\r\n",600);        //		AT_write(pubco2);
//        ESP8266_SendCmd(pubco2, "OK");
////    OLED_ShowNum(100,3,1,2,16,0);
//	}
//        sprintf(pubtemp,"AT+MQTTPUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"SERVER\\\"\\,\\\"properties\\\":{\\\"temp\\\":%d}}]}\",0,0\r\n",temp);
//		ESP8266_SendCmd(pubtemp, "OK");
////      AT_write(pubtemp);
//        sprintf(pubhumidity,"AT+MQTTPUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"SERVER\\\"\\,\\\"properties\\\":{\\\"humidity\\\":%d}}]}\",0,0\r\n",humidity);
//        ESP8266_SendCmd(pubhumidity, "OK");
////		AT_write(pubhumidity);
//        sprintf(pubco2,"AT+MQTTPUB=0,\"$oc/devices/67c05fc124d772325520f98a_000000/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"SERVER\\\"\\,\\\"properties\\\":{\\\"co2\\\":%d}}]}\",0,0\r\n",co2);        //		AT_write(pubco2);
//        ESP8266_SendCmd(pubco2, "OK");



        sprintf(pubtemp,"AT+MQTTPUB=0,\"$oc/devices/67bd7f9b8e04aa0690b7e606_shebei2/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"server\\\"\\,\\\"properties\\\":{\\\"temp\\\":%d}}]}\",0,0\r\n",temp);
		ESP8266_SendCmd(pubtemp, "OK");
//      AT_write(pubtemp);
        sprintf(pubhumidity,"AT+MQTTPUB=0,\"$oc/devices/67bd7f9b8e04aa0690b7e606_shebei2/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"server\\\"\\,\\\"properties\\\":{\\\"humidity\\\":%d}}]}\",0,0\r\n",humidity);
        ESP8266_SendCmd(pubhumidity, "OK");
//		AT_write(pubhumidity);
        sprintf(pubco2,"AT+MQTTPUB=0,\"$oc/devices/67bd7f9b8e04aa0690b7e606_shebei2/sys/properties/report\",\"{\\\"services\\\":[{\\\"service_id\\\":\\\"server\\\"\\,\\\"properties\\\":{\\\"co2\\\":%d}}]}\",0,0\r\n",co2);        //		AT_write(pubco2);
        ESP8266_SendCmd(pubco2, "OK");
        OLED_ShowNum(100,3,1,2,16,0);
}
/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
